package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.annotation.DataSource;
import com.ruoyi.common.enums.DataSourceType;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.CourseActivity;
import com.ruoyi.system.service.ICourseActivityService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 活动课程Controller
 * 
 * @author ruoyi
 * @date 2025-05-20
 */
@DataSource(DataSourceType.SLAVE_COURSE)
@RestController
@RequestMapping("/system/activity")
public class CourseActivityController extends BaseController
{
    @Autowired
    private ICourseActivityService courseActivityService;

    /**
     * 查询活动课程列表
     */
    @PreAuthorize("@ss.hasPermi('system:activity:list')")
    @GetMapping("/list")
    public TableDataInfo list(CourseActivity courseActivity)
    {
        startPage();
        List<CourseActivity> list = courseActivityService.selectCourseActivityList(courseActivity);
        return getDataTable(list);
    }

    /**
     * 导出活动课程列表
     */
    @PreAuthorize("@ss.hasPermi('system:activity:export')")
    @Log(title = "活动课程", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CourseActivity courseActivity)
    {
        List<CourseActivity> list = courseActivityService.selectCourseActivityList(courseActivity);
        ExcelUtil<CourseActivity> util = new ExcelUtil<CourseActivity>(CourseActivity.class);
        util.exportExcel(response, list, "活动课程数据");
    }

    /**
     * 获取活动课程详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:activity:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(courseActivityService.selectCourseActivityById(id));
    }

    /**
     * 新增活动课程
     */
    @PreAuthorize("@ss.hasPermi('system:activity:add')")
    @Log(title = "活动课程", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CourseActivity courseActivity)
    {
        return toAjax(courseActivityService.insertCourseActivity(courseActivity));
    }

    /**
     * 修改活动课程
     */
    @PreAuthorize("@ss.hasPermi('system:activity:edit')")
    @Log(title = "活动课程", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CourseActivity courseActivity)
    {
        return toAjax(courseActivityService.updateCourseActivity(courseActivity));
    }

    /**
     * 删除活动课程
     */
    @PreAuthorize("@ss.hasPermi('system:activity:remove')")
    @Log(title = "活动课程", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(courseActivityService.deleteCourseActivityByIds(ids));
    }
}
